//
//  ViewController.m
//  10-UITableViewCell自定义
//
//  Created by 402030900@qq.com on 16/7/27.
//  Copyright © 2016年 402030900@qq.com. All rights reserved.
//

#import "ViewController.h"
#import "CustomTableViewCell.h"
#import "NewsObject.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong)NSMutableArray * nameArr;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"自定义cell";
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
    _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:(UITableViewStylePlain)];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerClass:[CustomTableViewCell class] forCellReuseIdentifier:@"cell"];
    //使用自定义cell需要修改
    // 1.注册对应的cell的类型
    // 2.重用池取出cell的类型
    // 3.自定义cell继承于UITableViewCell
    // 数据的传递依赖于Model,传对象存对象去翠香
    NewsObject * newsObject = [[NewsObject alloc]initWithNewsImage:@"died" NewsTitle:@"123" NesDescription:@"456" NewsNumberCount:@"789"];
    self.nameArr = [NSMutableArray arrayWithObjects:newsObject,newsObject, nil];
    // 多种cell混合使用
    // 注册cell时 注意重用标识不要相同
    [_tableView registerClass:[CustomTableViewCell class] forCellReuseIdentifier:@"customCell"];
    
    
    
    
    
    
    
    
    
    
//    
//    NSArray *arr = @[@"唐益梦", @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"李毅然", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪"];
//    self.nameArr = [NSMutableArray arrayWithArray:arr];
    // Do any additional setup after loading the view, typically from a nib.
}
#warning 编辑
-(void)setEditing:(BOOL)editing animated:(BOOL)animated{
    [super setEditing:editing animated:animated];
    [_tableView setEditing:editing animated:animated];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _nameArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    // 多种cell同时使用时,可以根据下标决定样式
    // 判断情况一定要判断完整
    if (indexPath.row == 1) {
        CustomTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"customCell"];
        return cell;
    }else{
        
    CustomTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        
    cell.newsObject = _nameArr[indexPath.row];
          return cell;
    }
  }
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
